/**
 * 后台接口
 * @type {string}
 */
const baseUrl = 'https://m.nocexpo.com';
// const baseUrl = 'http://localhost:8085';
// const baseUrl = 'http://local.nocexpo.com';
// const baseUrl = 'http://test.noctech.cn';
export default {
	baseUrl,
	request({
		url,
		data,
		loading = false,
		loadingText = "",
		allResult = false,
		isToken = true,
		method="POST"
	} = {}) {
		return new Promise(async (resolve, reject) => {
			uni.request({
				url: baseUrl+url,
				data: data,
				method: method,
				dataType: "json",
				timeout: 10000,
				header: {
					"Content-Type": 'application/json', // 默认值
					"token": uni.getStorageSync("authorize").token,
					cookie: uni.getStorageSync('cookie')
				},
				success: async (result) => {
					if(url.indexOf("getwxacode")>0){
					}

					if (loading || loadingText) {
						uni.hideLoading()
					}
					if (allResult == true) { //在请求调用处，处理所有逻辑
						resolve(result.data);
					} else {
						//请求成功
						if (result.data.code == 0) {
							resolve(result);
						}  else { //未知错误
							if (result.data && result.data.msg) {
								uni.showToast({
									"title": result.data.msg,
									"icon": "none",
								});
							}
							reject(result.data);
						}
					}
				},
				fail: (e) => {
					let remark = "系统错误",
						errMsg = e.errMsg;
					if (loading || loadingText) {
						uni.hideLoading()
					}
					if (e.errMsg == "request:fail timeout") {
						uni.showToast({
							"title": "系统繁忙，请稍后再试",
							"icon": "none",
						});
						remark = "网络丢失";
					}
				},
				complete: (res) => {
				}
			})

		});
	}
}
